package com.frejoys.app.controller;

import com.frejoys.common.aop.Authority;
import com.frejoys.common.aop.Authorization;
import com.frejoys.common.constant.CommonConstant;
import com.frejoys.common.dto.app.CodeDto;
import com.frejoys.common.response.Result;
import com.frejoys.common.vo.app.StoreIdVo;
import com.frejoys.service.StoreCodeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "开放接口", description = "开放接口")
@RestController
@RequiredArgsConstructor
@RequestMapping(CommonConstant.routePrefixApp)
@Authorization(Authority.Open)
public class OpenController {

    private final StoreCodeService storeCodeService;

   @PostMapping("/open/getStoreIdInfo")
   @Operation(summary = "根据支付码code获取店铺id")
   public Result<StoreIdVo> getStoreIdInfo(@RequestBody @Validated CodeDto dto){
       Integer storeId = storeCodeService.getStoreId(dto.getCode());
       if (storeId != null) {
           StoreIdVo vo = new StoreIdVo(){{
               setStoreId(storeId);
           }};
           return Result.success(vo);
       }
       return Result.success();
   }
}
